<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.*, cn.school.mybatis.pojo.Student" %>    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
</head>
<body>
<%-- <%@include file="/checkLogin.jsp" %> --%>
<p align="right">
<!--  <a href="addStudent.jsp">添加新生</a> -->
 <a href="toAddStudentServlet">添加新生</a>
</p>
<img src="<%=request.getContextPath()%>/images/5.jpg" height="200px" />
<img src="${pageContext.request.contextPath}/images/3.jpg" height="200px" />

<%-- <%
   pageContext.getRequest()
   //request.getAttribute("contextPath");
%> --%>
<%


int pageNo=(Integer)request.getAttribute("pageNo");
//int pageSize=10;
 

String sname=(String)request.getAttribute("sname");
String telephone=(String)request.getAttribute("telephone");

List<Student> list =(List<Student>)request.getAttribute("list"); 
int totalPage=(Integer)request.getAttribute("totalPage");
 
%>
<p id="search">
 <form method="get" action="studentServlet">
  <input name="sname" value="${sname}" placeholder="姓名"/>
  <input name="telephone" value="${telephone}" placeholder="电话号码"/>
  <input type="submit" value="搜索"/>
 </form>
</p>
<table width="80%" border="1" cellspacing="0" cellpadding="0"> 
 <tr>
  <td>学号</td>
  <td>姓名</td>
  <td>性别</td>
  <td>操作</td>
 </tr>
<%

for(Student s:list){
%>
 <tr>
  <td><%=s.getId() %></td>
  <td><%=s.getSname() %></td>
  <td><%=s.getSex()%></td>
  <td>
  <a href="showStudent?stuno=<%=s.getId()%>" >查看</a>
    <a href="toUpdateStudent.jsp?stuno=<%=s.getId()%>">修改</a>
    <a href="toDelStudent.jsp?stuno=<%=s.getId()%>" onclick="return confirm('真的要删除<%=s.getSname() %>?');">删除</a>
  </td>
 </tr>
<%} %>
</table>
<p align="right" style="margin-right:200px">
 <a href="studentServlet?p=1&sname=<%=sname%>&telephone=<%=telephone%>">首页</a>
 <% if(pageNo>1) {%>
   <a href="studentServlet?p=<%=pageNo-1%>&sname=<%=sname%>&telephone=<%=telephone%>">上一页</a>
 <%} %>
 <input type="number" min="1" max="<%=totalPage%>" value="<%=pageNo%>" name="p" style="width:30px"/>/<%=totalPage%>
 <input type="button" id="go" value="go"/>
 <%
   if(pageNo<totalPage){
 %> 
   <a href="studentServlet?p=<%=pageNo+1%>&sname=<%=sname%>&telephone=<%=telephone%>">下一页</a>
  <%} %>
   <a href="studentServlet?p=<%=totalPage%>&sname=<%=sname%>&telephone=<%=telephone%>">尾页</a>
</p>
<script>
 $(function(){
	 $("#go").click(function(){
		 let p=$(this).prev().val();
		 //p在 1 和 totalPage 之间
		 window.location='studentServlet?p='+p+'&sname=<%=sname%>&telephone=<%=telephone%>';
	 });
 });
</script>

</body>
</html>